package org.cwx.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.chen.bean.UserMessageBean;
import org.cwx.service.impl.ILoginServiceImpl;
import org.cwx.utils.MyUtils;

/**
 * 个人信息新增
 */
@WebServlet("/PerinfoAction")
public class PerinfoAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 业务信息处理
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 1、接收表单数据
		UserMessageBean adminB = MyUtils.convertFormData2Bean(request, UserMessageBean.class);
		adminB.setUsertel(String.valueOf(request.getSession().getAttribute("userTel")));
		// 2、调用service层进行数据保存
		System.out.println("adminB:" + adminB);
		int i = MyUtils.getInstance(ILoginServiceImpl.class).saveOrUpdateAdminInf(adminB);
		System.out.println("i:" + i);
		// 3、根据保存处理结果进行页面转发
		if (i > 0) {
			// 保存成功
			request.getSession().setAttribute("userTel", adminB.getUsertel());
			request.getSession().setAttribute("userName", adminB.getUsername());
			request.getSession().setAttribute("userSex", adminB.getUsersex());
			request.getSession().setAttribute("userRealname", adminB.getUserrealname());
			request.getSession().setAttribute("userIdcard", adminB.getUseridcard());
			response.sendRedirect("cwx/perinfo.jsp");
		} 
	}

}
